def mad_libs(file_path):
    # 读取文本文件
    with open(file_path, 'r') as file:
        content = file.read()

    # 查找并替换关键词
    keywords = ['ADJECTIVE', 'NOUN', 'ADVERB', 'VERB']
    for keyword in keywords:
        while keyword in content:
            replacement = input(f'Enter {("an " if keyword[0] in "AEIOU" else "a ")}{keyword.lower()}: ')
            content = content.replace(keyword, replacement, 1)

    # 打印填充后的文本
    print("\nMad Libs Result:")
    print(content)

    # 将结果写入新文件
    with open('mad_libs_result.txt', 'w') as result_file:
        result_file.write(content)

# 调用函数，传入文本文件路径
mad_libs('example.txt')
